package DCSource.Template.SRC;

import javax.swing.JComponent;

public class Converter {
	public double p1;
	public double p2;
	public double p3;
	public double p4;
	public Converter(double StartXPercent,double StartYPercent, double WidthPercent, double HighPercent){
		if (StartXPercent>100){
			StartXPercent=1;
		}
		if (StartXPercent>1){
			StartXPercent/=100;
		}
		p1 = StartXPercent;
		if (StartYPercent>100){
			StartYPercent=1;
		}
		if (StartYPercent>1){
			StartYPercent/=100;
		}
		p2 = StartYPercent;
		if (WidthPercent>100){
			WidthPercent=1;
		}
		if (WidthPercent>1){
			WidthPercent/=100;
		}
		p3 = WidthPercent;
		if (HighPercent>100){
			HighPercent=1;
		}
		if (HighPercent>1){
			HighPercent/=100;
		}
		p4 = HighPercent;
	}
	public void ConvertIn(int Height, int Width, JComponent toConvert){
		toConvert.setBounds((int)Math.round(Width*p1),(int)Math.round(p2*Height),(int)Math.round(p3*Width),(int)Math.round(p4*Height));
	}
	public void ConvertInWithRand(int Height, int Width, JComponent toConvert, int RandY, int RandX){
		Height-=RandY*2;
		Width-=RandX*2;
		toConvert.setBounds((int)Math.round(Width*p1)+RandX,(int)Math.round(p2*Height)+RandY,(int)Math.round(p3*Width)-RandX*3,(int)Math.round(p4*Height)-RandY*3);
	}
}
